<template>
  <div>
    <div v-if="groupStatus">
      <van-empty image="network" description="暂不支持群组信息查询" />
    </div>

    <div v-if="!groupStatus">
      <div v-if="indexError">
        <van-empty image="error" description="服务器繁忙，请稍后尝试" />
      </div>

      <div v-if="!indexError">
        <van-loading
          size="48px"
          v-if="indexLoading"
          style="margin-left: 32%; margin-top: 25%"
          >加载中...</van-loading
        >

        <div class="bg" v-if="!indexLoading">
          <van-row v-if="tagList.length > 0">
            <div style="margin-top: 15px; margin-left: 15px">
              <van-tag
                v-for="tag in tagList"
                :key="tag"
                size="large"
                plain
                color="#17C08A"
                text-color="#17C08A"
                class="margin-right10"
              >
                <label>{{ tag }}</label>
              </van-tag>
            </div>
          </van-row>
          <van-row v-if="clinicName">
            <div style="margin-top: 8px; margin-left: 15px">
              <label style="font-size: 13pt; color: #666666">{{
                clinicName
              }}</label>
            </div>
          </van-row>
          <van-row v-if="phone" style="margin-bottom: 10px">
            <div style="margin-top: 8px; margin-left: 15px">
              <label style="font-size: 13pt; color: #666666"
                >手机号码：{{ phone }}
              </label>
            </div>
          </van-row>
          <van-row v-if="tagList.length > 0">
            <van-tabs
              :active="active"
              @change="onTabChange"
              color="#26DBDF"
              background="#E5FAFD"
              shrink
            >
              <van-tab name="tab1" title="客户状态">
                <div style="background-color: #f2f2f6">
                  <van-cell-group inset>
                    <van-field
                      label="最近一次登录日期"
                      label-width="8em"
                      size="large"
                      autosize="true"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastLoginTime !== '' &&
                            lastLoginTime !== undefined &&
                            lastLoginTime !== null
                              ? lastLoginTime
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="钱包"
                      size="large"
                      autosize="true"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            wallet !== '' &&
                            wallet !== undefined &&
                            wallet !== null
                              ? wallet
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="会员等级"
                      size="large"
                      autosize="true"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            memberLevel !== '' &&
                            memberLevel !== undefined &&
                            memberLevel !== null
                              ? memberLevel
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="会员状态"
                      size="large"
                      autosize="true"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            memberStatus !== '' &&
                            memberStatus !== undefined &&
                            memberStatus !== null
                              ? memberStatus
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="会员权益"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                    >
                      <template #input>
                        <div>
                          {{ memberBenefitList.length > 0 ? '' : '无' }}
                          <u
                            v-if="memberBenefitList.length > 0"
                            @click="openMemberBenefitDetail"
                            style="color: red"
                          >
                            {{ memberBenefitList.length + '项' }}
                          </u>
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="总业绩"
                      size="large"
                      label-width="5em"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{ performanceMoneyTotal > 0 ? '' : '无' }}
                          <u
                            v-if="performanceMoneyTotal > 0"
                            @click="openPerformanceMoneyDetail"
                            style="color: red"
                          >
                            {{ '￥' + performanceMoneyTotal }}
                          </u>
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次下单时间"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastPayTime !== '' &&
                            lastPayTime !== undefined &&
                            lastPayTime !== null
                              ? lastPayTime
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="跟进总次数"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{ trackTotal > 0 ? '' : '无' }}
                          <u
                            v-if="trackTotal > 0"
                            @click="openTrackDetail"
                            style="color: red"
                          >
                            {{ trackTotal + '次' }}
                          </u>
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次跟进时间"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastTrackTime !== '' &&
                            lastTrackTime !== undefined &&
                            lastTrackTime !== null
                              ? lastTrackTime
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次备注"
                      label-width="8em"
                      size="large"
                      autosize="true"
                      type="textarea"
                      rows="1"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastTrackRemark !== '' &&
                            lastTrackRemark !== undefined &&
                            lastTrackRemark !== null
                              ? lastTrackRemark
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="客诉总次数"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                    >
                      <template #input>
                        <div>
                          {{ appealTotal > 0 ? '' : '无' }}
                          <u
                            v-if="appealTotal > 0"
                            @click="openAppealDetail"
                            style="color: red"
                          >
                            {{ appealTotal + '次' }}
                          </u>
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次客诉时间"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastAppealTime !== '' &&
                            lastAppealTime !== undefined &&
                            lastAppealTime !== null
                              ? lastAppealTime
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次客诉状态"
                      label-width="8em"
                      size="large"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastAppealStatus !== '' &&
                            lastAppealStatus !== undefined &&
                            lastAppealStatus !== null
                              ? lastAppealStatus
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="最近一次客诉内容"
                      size="large"
                      autosize="true"
                      label-width="8em"
                      type="textarea"
                      rows="1"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastAppealContent !== '' &&
                            lastAppealContent !== undefined &&
                            lastAppealContent !== null
                              ? lastAppealContent
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                    <van-field
                      label="客诉处理内容"
                      size="large"
                      autosize="true"
                      label-width="8em"
                      type="textarea"
                      rows="1"
                      label-class="card-font-label"
                      input-align="right"
                      readonly
                    >
                      <template #input>
                        <div>
                          {{
                            lastDisposeContent !== '' &&
                            lastDisposeContent !== undefined &&
                            lastDisposeContent !== null
                              ? lastDisposeContent
                              : '无'
                          }}
                        </div>
                      </template>
                    </van-field>
                  </van-cell-group>
                </div>
                <br />
              </van-tab>
              <van-tab name="tab2" title="客户订单">
                <div style="background-color: #f2f2f6">
                  <van-search
                    v-model="orderKeywords"
                    show-action
                    shape="round"
                    background="#E5FAFD"
                    left-icon="https://uploads.caiyaome.com/miniprogram/cim/search.png"
                    placeholder="搜索厂商"
                    @search="orderSeach"
                  >
                    <template #action>
                      <div
                        @click="getOrderList(1)"
                        style="
                          width: 100px;
                          text-align: center;
                          border-radius: 35px;
                          background-color: #17c08a;
                        "
                      >
                        搜索
                      </div>
                    </template>
                  </van-search>
                  <van-pagination
                    v-if="orderPage.total > 0"
                    v-model="orderPage.current"
                    :show-page-size="orderPage.size"
                    :page-count="orderPage.pages"
                    mode="simple"
                    @change="changeOrderPage"
                    class="margin-top10"
                    style="margin-left: 5px; margin-right: 10px"
                  />
                  <div v-if="orderList.length > 0">
                    <div v-for="order in orderList" :key="order">
                      <van-row
                        style="
                          background-color: white;
                          height: 40px;
                          margin-left: 10px;
                          margin-right: 10px;
                          margin-top: 10px;
                          display: flex;
                        "
                      >
                        <div
                          style="
                            padding-top: 10px;
                            padding-left: 8px;
                            width: 75%;
                            text-align: left;
                            font-size: 18px;
                            font-weight: bold;
                          "
                        >
                          {{ order.supplierName }}
                        </div>
                        <div
                          style="
                            width: 25%;
                            text-align: right;
                            font-size: 15px;
                            padding-right: 8px;
                            padding-top: 10px;
                          "
                        >
                          {{ order.orderStatus }}
                        </div>
                      </van-row>
                      <van-row
                        style="
                          background-color: white;
                          height: 30px;
                          margin-left: 10px;
                          margin-right: 10px;
                          display: flex;
                        "
                      >
                        <div
                          style="
                            margin-left: 8px;
                            width: 56%;
                            text-align: left;
                            color: #666666ff;
                          "
                        >
                          订单时间:{{ order.createTime }}
                        </div>
                        <div
                          style="
                            padding-right: 8px;
                            width: 44%;
                            text-align: right;
                            font-size: 18px;
                            font-weight: bold;
                          "
                        >
                          <label
                            v-if="order.orderStatus != '已退款'"
                            style="color: red"
                          >
                            ￥{{ order.orderMoney }}
                          </label>
                          <label
                            v-if="order.orderStatus == '已退款'"
                            style="color: #999999ff"
                          >
                            ￥{{ order.orderMoney }}
                          </label>
                        </div>
                      </van-row>
                    </div>
                    <br />
                  </div>
                </div>
                <van-empty
                  v-if="orderPage.total == 0"
                  description="暂无数据"
                  style="height: 100%"
                />
              </van-tab>
              <van-tab name="tab3" title="颗粒商品">
                <div style="background-color: #f2f2f6">
                  <div style="display: flex">
                    <van-search
                      v-model="goodsNameKeywords"
                      shape="round"
                      left-icon="https://uploads.caiyaome.com/miniprogram/cim/search.png"
                      clearable
                      background="#E5FAFD"
                      placeholder="搜索品名"
                      style="height: 54px; width: 74%"
                      @search="goodsNameSeach"
                    />

                    <van-dropdown-menu
                      style="
                        width: 26%;
                        background-color: #e5fafd;
                        padding-right: 10px;
                        height: 50px;
                      "
                    >
                      <van-dropdown-item
                        v-model="dateValue"
                        :options="dateList"
                        @change="dateChange"
                      />
                    </van-dropdown-menu>
                  </div>

                  <van-pagination
                    v-if="goodsNamePage.total > 0"
                    v-model="goodsNamePage.current"
                    :show-page-size="goodsNamePage.size"
                    :page-count="goodsNamePage.pages"
                    mode="simple"
                    @change="changeGoodsNamePage"
                    class="margin-top10"
                    style="margin-left: 5px; margin-right: 10px"
                  />

                  <div v-if="goodsNameList.length > 0" style="margin-top: 10px">
                    <div v-for="item in goodsNameList" :key="item">
                      <van-row
                        style="
                          background-color: white;
                          height: 60px;
                          margin-left: 10px;
                          margin-right: 10px;
                          margin-bottom: 10px;
                          display: flex;
                        "
                      >
                        <div
                          style="
                            padding-top: 10px;
                            padding-left: 15px;
                            width: 55%;
                            text-align: left;
                          "
                        >
                          <van-row
                            style="
                              font-size: 18px;
                              font-weight: bold;
                              margin-bottom: 5px;
                            "
                          >
                            {{ item.goodsName }}
                          </van-row>
                          <van-row>
                            <van-tag
                              v-for="tag in item.packType.split(',')"
                              :key="tag"
                              plain
                              color="#17C08A"
                              text-color="#17C08A"
                              class="margin-right10"
                            >
                              <label>{{ tag }}</label>
                            </van-tag>
                          </van-row>
                        </div>

                        <div
                          style="
                            width: 45%;
                            text-align: right;
                            padding-right: 15px;
                            padding-top: 10px;
                          "
                        >
                          商品金额<br />
                          <label style="font-size: 20px; color: red"
                            >￥{{ item.goodsNameMoney }}</label
                          >
                        </div>
                      </van-row>
                    </div>
                  </div>
                </div>
                <van-empty
                  v-if="goodsNameList.length <= 0"
                  description="暂无数据"
                  style="height: 100%"
                />
              </van-tab>
            </van-tabs>

            <van-popup
              v-model="memberBenefitShow"
              round
              style="max-height: 380px; width: 350px"
            >
              <van-row class="margin-top10" style="height: 45px">
                <div
                  style="
                    height: 100%;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/memberBenefit.png');
                  "
                ></div>
              </van-row>
              <van-row
                style="
                  max-height: 271px;
                  margin-top: 10px;
                  margin-left: 30px;
                  font-size: 16px;
                "
              >
                <div v-for="(item, index) in memberBenefitList" :key="item">
                  <p style="margin-bottom: 10px">{{ index + 1 }}. {{ item }}</p>
                </div>
              </van-row>
              <van-row
                @click="closeMemberBenefitDetail"
                style="
                  position: relative;
                  height: 44px;
                  padding: 0 0 !important;
                  background-size: cover;
                  background-repeat: no-repeat;
                  background-position: center;
                  background-image: url('https://uploads.caiyaome.com/miniprogram/cim/confirm.png');
                "
              >
              </van-row>
            </van-popup>
            <van-popup
              v-model="performanceMoneyShow"
              round
              style="max-height: 390px; width: 350px"
            >
              <van-row class="margin-top10" style="height: 45px">
                <div
                  style="
                    height: 100%;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/performanceMoney.png');
                  "
                ></div>
              </van-row>
              <van-row
                style="max-height: 271px; margin: 10px 20px; font-size: 16px"
              >
                <div v-for="item in performanceMoneyList" :key="item">
                  <van-field
                    :label="item.goodsTypeName"
                    size="large"
                    label-width="8em"
                    autosize="true"
                    label-class="card-font-label"
                    input-align="right"
                    readonly
                  >
                    <template #input>
                      <div style="color: red; font-size: 16px">
                        ￥{{ item.performanceMoney }}
                      </div>
                    </template>
                  </van-field>
                </div>
              </van-row>
              <van-row
                @click="closePerformanceMoneyDetail"
                style="
                  position: relative;
                  height: 44px;
                  padding: 0 0 !important;
                  background-size: cover;
                  background-repeat: no-repeat;
                  background-position: center;
                  background-image: url('https://uploads.caiyaome.com/miniprogram/cim/confirm.png');
                "
              >
              </van-row>
            </van-popup>
            <van-popup
              v-model="trackShow"
              round
              style="max-height: 650px; width: 350px"
            >
              <van-row class="margin-top10" style="height: 45px">
                <div
                  style="
                    height: 100%;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/trackRecord.png');
                  "
                ></div>
              </van-row>
              <van-row style="margin: 10px 5px; font-size: 16px">
                <div
                  v-for="item in trackList"
                  :key="item"
                  style="max-height: 500px"
                >
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="跟进时间"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.trackTime"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="跟进人员"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.trackEmployee"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="跟进结果"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.trackResult"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />

                    <van-field
                      label="跟进备注"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      type="textarea"
                      rows="1"
                      v-model="item.trackRemark"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                  </van-cell-group>
                </div>

                <van-empty
                  v-if="trackPage.total == 0"
                  style="height: 200px"
                  description="暂无数据"
                />
              </van-row>
              <van-row style="max-height: 100px; position: relative">
                <van-pagination
                  v-if="trackPage.total > 0"
                  v-model="trackPage.current"
                  :show-page-size="trackPage.size"
                  :page-count="trackPage.pages"
                  mode="simple"
                  @change="changeTrackPage"
                  style="margin-top: 10px; margin: 0px 20px"
                />
                <br />
                <div
                  @click="closeTrackDetail"
                  style="
                    height: 44px;
                    padding: 0 0 !important;
                    background-size: cover;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/confirm.png');
                  "
                ></div>
              </van-row>
            </van-popup>
            <van-popup
              v-model="appealShow"
              round
              style="max-height: 600px; width: 350px"
            >
              <van-row class="margin-top10" style="height: 45px">
                <div
                  style="
                    height: 100%;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/appealRecord.png');
                  "
                ></div>
              </van-row>
              <van-row style="margin: 10px 5px; font-size: 16px">
                <div
                  v-for="item in appealList"
                  :key="item"
                  style="max-height: 400px"
                >
                  <van-cell-group inset class="margin-top10">
                    <van-field
                      label="投诉时间"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.appealTime"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="投诉状态"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.appealStatus"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="投诉内容"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      type="textarea"
                      rows="1"
                      v-model="item.appealContent"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="处理时间"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      v-model="item.disposeTime"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                    <van-field
                      label="处理内容"
                      size="large"
                      label-width="6em"
                      autosize="true"
                      type="textarea"
                      rows="1"
                      v-model="item.disposeContent"
                      label-class="card-font-label"
                      input-align="right"
                      style="background-color: #f7f7f7ff"
                      readonly
                    />
                  </van-cell-group>
                </div>

                <van-empty
                  v-if="appealPage.total == 0"
                  style="height: 200px"
                  description="暂无数据"
                />
              </van-row>
              <van-row style="max-height: 100px; position: relative">
                <van-pagination
                  v-if="appealPage.total > 0"
                  v-model="appealPage.current"
                  :show-page-size="appealPage.size"
                  :page-count="appealPage.pages"
                  mode="simple"
                  @change="changeAppealPage"
                  style="margin-top: 10px; margin: 0px 20px"
                />
                <br />
                <div
                  @click="closeAppealDetail"
                  style="
                    height: 44px;
                    padding: 0 0 !important;
                    background-size: cover;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-image: url('https://uploads.caiyaome.com/miniprogram/cim/confirm.png');
                  "
                ></div>
              </van-row>
            </van-popup>
          </van-row>
          <van-row v-if="tagList.length <= 0">
            <van-empty
              image="https://uploads.caiyaome.com/miniprogram/cim/anonymous.png"
              description=""
            />
          </van-row>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getWeCustomerBaseInfo } from '../../api/portrait';
import {
  getClinicBaseInfo,
  getClinicTrackPage,
  getClinicAppealPage,
  getClinicOrderPage,
  getClinicOrderGoodsNamePage,
} from '../../api/cim';
import { param2Obj } from '../../utils/index';

export default {
  components: {},
  provide() {
    return {
      getExternalUserId: () => this.externalUserid,
    };
  },
  data() {
    return {
      externalUserid: '',

      groupStatus: false,
      indexError: false,

      indexLoading: false,

      active: 'tab1',
      tagList: [],
      clinicName: '',
      phone: '',
      userUnionid: '',

      clinicId: '',
      lastLoginTime: '',
      wallet: '',
      memberLevel: '',
      memberStatus: '',
      memberBenefitList: [],
      memberBenefitShow: false,

      performanceMoneyTotal: 0,
      performanceMoneyList: [],
      performanceMoneyShow: false,
      lastPayTime: '',

      trackTotal: 0,
      lastTrackTime: '',
      lastTrackRemark: '',
      trackShow: false,
      trackPage: { current: 1, pages: 0, size: 2, total: 0 },
      trackList: [],

      appealTotal: 0,
      lastAppealTime: '',
      lastAppealStatus: '',
      lastAppealContent: '',
      lastDisposeContent: '',
      appealShow: false,
      appealPage: { current: 1, pages: 0, size: 1, total: 0 },
      appealList: [],

      orderKeywords: '',
      orderPage: { current: 1, pages: 0, size: 7, total: 0 },
      orderList: [],

      goodsNamePage: { current: 1, pages: 0, size: 8, total: 0 },
      dateList: [
        { text: '半年内', value: 6 },
        { text: '一年内', value: 12 },
      ],
      dateValue: 6,
      goodsNameKeywords: '',
      goodsNameList: [],
    };
  },

  computed: {
    // localDebugStart
    userId() {
      return this.$store.state.userId;
    },
    // localDebugEnd
  },

  watch: {
    // localDebugStart
    '$store.state.agentConfigStatus'(val) {
      val && this.init();
    },
    // localDebugEnd
  },

  mounted() {},

  created() {
    // localDebugStart
    this.$toast.loading({
      message: 'loading...',
      duration: 0,
      forbidClick: true,
    });
    // 获取agentId
    let query = param2Obj(window.location.search);
    const hash = param2Obj(window.location.hash);
    query = Object.assign(query, hash);
    this.agentId = query.agentId;
    if (this.$store.state.agentConfigStatus && this.isLock) {
      this.init();
    }
    // localDebugEnd
  },
  methods: {
    openPerformanceMoneyDetail() {
      this.performanceMoneyShow = true;
    },
    closePerformanceMoneyDetail() {
      this.performanceMoneyShow = false;
    },

    openMemberBenefitDetail() {
      this.memberBenefitShow = true;
    },
    closeMemberBenefitDetail() {
      this.memberBenefitShow = false;
    },

    openTrackDetail() {
      this.getTrackList(1);
      this.trackShow = true;
    },
    closeTrackDetail() {
      this.trackShow = false;
    },

    changeTrackPage(page) {
      this.getTrackList(page);
    },

    openAppealDetail() {
      this.getAppealList(1);
      this.appealShow = true;
    },
    closeAppealDetail() {
      this.appealShow = false;
    },
    changeAppealPage(page) {
      this.getAppealList(page);
    },

    init() {
      const _this = this;
      _this.$api.invoke('getContext', {}, function (res) {
        if (res.err_msg === 'getContext:ok') {
          const entry = res.entry; // 返回进入H5页面的入口类型，目前有normal、contact_profile、single_chat_tools、group_chat_tools
          _this.portraitType =
            entry === 'group_chat_tools' ? 'group' : 'customer';

          if (_this.portraitType === 'group') {
            _this.groupStatus = true;
            _this.$toast.clear();
          } else {
            _this.$api.invoke('getCurExternalContact', {}, (res) => {
              if (res.err_msg === 'getCurExternalContact:ok') {
                _this.externalUserid = res.userId; // 返回当前外部联系人userId
                // 获取客户信息
                _this.$store.dispatch('GetCustomerProperty');
                _this.getWeCustomerBaseInfo();
              } else {
                // 错误处理
                _this.$dialog({
                  message: '进入失败：' + JSON.stringify(res),
                });
              }
              _this.$toast.clear();
            });
          }
        } else {
          // 错误处理
          _this.indexError = true;
          _this.$toast.clear();
          _this.$dialog({ message: '进入失败：' + JSON.stringify(res) });
        }
      });
    },

    getClinicBaseInfo() {
      getClinicBaseInfo({
        unionId: this.userUnionid,
      })
        .then(({ data }) => {
          if (data.clinicId !== null) {
            this.clinicId = data.clinicId;
            this.lastLoginTime = data.lastLoginTime;
            this.wallet = data.wallet;
            this.memberLevel = data.memberLevel;
            this.memberStatus = data.memberStatus;
            this.memberBenefitList = data.memberBenefitList;
            this.performanceMoneyTotal = data.performanceMoneyTotal;
            this.performanceMoneyList = data.performanceMoneyList;
            this.lastPayTime = data.lastPayTime;
            this.trackTotal = data.trackTotal;
            this.lastTrackTime = data.lastTrackTime;
            this.lastTrackRemark = data.lastTrackRemark;
            this.appealTotal = data.appealTotal;
            this.lastAppealTime = data.lastAppealTime;
            this.lastAppealStatus = data.lastAppealStatus;
            this.lastAppealContent = data.lastAppealContent;
            this.lastDisposeContent = data.lastDisposeContent;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    getTrackList(page) {
      this.trackPage.current = page;
      this.trackPage.total = 0;
      this.trackPage.pages = 0;
      this.trackList = [];
      this.getClinicTrackPage();
    },

    getClinicTrackPage() {
      if (this.clinicId != null || this.clinicId !== '') {
        getClinicTrackPage({
          clinicId: this.clinicId,
          page: this.trackPage.current,
          size: this.trackPage.size,
        })
          .then(({ data }) => {
            if (data !== null && data !== undefined) {
              this.trackPage.current = data.current;
              this.trackPage.pages = data.pages;
              this.trackPage.total = data.total;
              this.trackList = data.records;
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },

    getAppealList(page) {
      this.appealPage.current = page;
      this.appealPage.total = 0;
      this.appealPage.pages = 0;
      this.appealList = [];
      this.getClinicAppealPage();
    },

    getClinicAppealPage() {
      if (this.clinicId != null || this.clinicId !== '') {
        getClinicAppealPage({
          clinicId: this.clinicId,
          page: this.appealPage.current,
          size: this.appealPage.size,
        })
          .then(({ data }) => {
            if (data !== null && data !== undefined) {
              this.appealPage.current = data.current;
              this.appealPage.pages = data.pages;
              this.appealPage.total = data.total;
              this.appealList = data.records;
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },

    orderSeach(val) {
      this.orderKeywords = val;
      this.getOrderList(1);
    },

    changeOrderPage(page) {
      this.getOrderList(page);
    },

    getOrderList(page) {
      this.orderPage.current = page;
      this.orderPage.total = 0;
      this.orderPage.pages = 0;
      this.orderList = [];
      this.getClinicOrderPage();
    },

    getClinicOrderPage() {
      if (this.clinicId != null || this.clinicId !== '') {
        getClinicOrderPage({
          clinicId: this.clinicId,
          page: this.orderPage.current,
          size: this.orderPage.size,
          keywords: this.orderKeywords,
        })
          .then(({ data }) => {
            if (data !== null && data !== undefined) {
              this.orderPage.current = data.current;
              this.orderPage.pages = data.pages;
              this.orderPage.total = data.total;
              this.orderList = data.records;
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },

    dateChange(value) {
      this.dateValue = value;
      this.getGoodsNameList(1);
    },

    goodsNameSeach(val) {
      this.goodsNameKeywords = val;
      this.getGoodsNameList(1);
    },

    changeGoodsNamePage(page) {
      this.getGoodsNameList(page);
    },

    getGoodsNameList(page) {
      this.goodsNamePage.current = page;
      this.goodsNamePage.total = 0;
      this.goodsNamePage.pages = 0;
      this.goodsNameList = [];
      this.getClinicOrderGoodsNamePage();
    },

    getClinicOrderGoodsNamePage() {
      if (this.clinicId != null || this.clinicId !== '') {
        getClinicOrderGoodsNamePage({
          clinicId: this.clinicId,
          page: this.goodsNamePage.current,
          size: this.goodsNamePage.size,
          keywords: this.goodsNameKeywords,
          date: this.dateValue,
        })
          .then(({ data }) => {
            if (data !== null && data !== undefined) {
              this.goodsNamePage.current = data.current;
              this.goodsNamePage.pages = data.pages;
              this.goodsNamePage.total = data.total;
              this.goodsNameList = data.records;
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },

    getWeCustomerBaseInfo() {
      getWeCustomerBaseInfo({
        externalUserid: this.externalUserid,
        userId: this.userId,
      })
        .then(({ data }) => {
          if (data !== null && data !== undefined) {
            this.clinicName = data.remark;
            this.phone = data.remarkMobiles;
            this.userUnionid = data.unionid;
            if (
              data.weTagGroupList !== null &&
              data.weTagGroupList.length > 0
            ) {
              for (let i = 0; i < data.weTagGroupList.length; i++) {
                if (
                  data.weTagGroupList[i].weTags !== null &&
                  data.weTagGroupList[i].weTags.length > 0
                ) {
                  for (
                    let y = 0;
                    y < data.weTagGroupList[i].weTags.length;
                    y++
                  ) {
                    this.tagList.push(data.weTagGroupList[i].weTags[y].name);
                  }
                }
              }
            }
            this.getClinicBaseInfo();
          } else {
            this.indexError = true;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    onTabChange(name) {
      if (name === 'tab2') {
        this.changeTab2();
      }

      if (name === 'tab3') {
        this.changeTab3();
      }
    },

    changeTab2() {
      this.getOrderList(1);
    },
    changeTab3() {
      this.getGoodsNameList(1);
    },
  },
};
</script>
<style lang="less" scoped>
.layout {
  min-height: 100vh;
  min-height: -moz-available;
  min-height: -webkit-fill-available;
  min-height: fill-available;
}

.bg {
  max-height: 120px;
  width: 100%;
  background-image: url('https://uploads.caiyaome.com/miniprogram/cim/bgi.png');
  background-size: cover;
  position: absolute;
}

.margin-top10 {
  margin-top: 10px;
}

.margin-right10 {
  margin-right: 10px;
}

.card-font-label {
  color: #666666;
}

::v-deep .van-dropdown-menu__bar {
  position: relative !important;
  display: flex !important;
  height: 36px !important;
  margin-top: 8px;
  background-color: #fff !important;
  border-radius: 30px !important;
  box-shadow: 0 2px 12px rgba(100, 101, 102, 0.12) !important;
}

::v-deep .van-search__content {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  padding-left: 12px;
  background-color: #fff;
  border-radius: 14px;
}

::v-deep .van-search .van-cell .van-field__left-icon {
  color: #969799;
  margin-top: 4px;
}
</style>